package config

import (
	"github.com/spf13/viper"
	"log"
)

type Config struct {
	Mysql struct {
		User     string
		Password string
		Host     string
		Port     int
		Database string
	}
	Redis struct {
		Addr     string
		Password string
		Db       int
	}
	RabbitMQ struct {
		Url      string
		Username string
		Password string
		Vhost    string
	}
	BaiDu struct {
		ApiKey    string
		SecretKey string
	}
}

var AppConf Config

func InitViper() {
	viper.SetConfigFile("./config/dev.yaml")
	err := viper.ReadInConfig()
	if err != nil {
		panic("配置文件读取失败")
	}
	log.Println("配置文件读取成功")
	err = viper.Unmarshal(&AppConf)
	if err != nil {
		panic("配置文件解析失败")
	}
	log.Println("配置文件解析成功", AppConf)

}
